from typing import Optional, List
from pydantic import BaseModel, Field
from datetime import datetime


class BaseSchema(BaseModel):
    class Config:
        allow_population_by_field_name = True
        alias_generator = lambda x: ''.join(word.capitalize() if i else word for i, word in enumerate(x.split('_')))


class SysMenuBase(BaseSchema):

    menu_name: Optional[str] = Field("", alias="menuName")

    parent_id: Optional[int] = Field(None, alias="parentId")

    order_num: Optional[int] = Field(None, alias="orderNum")

    path: Optional[str] = Field(None, alias="path")

    component: Optional[str] = Field(None, alias="component")

    query: Optional[str] = Field(None, alias="query")

    route_name: Optional[str] = Field(None, alias="routeName")

    is_frame: Optional[int] = Field(None, alias="isFrame")

    is_cache: Optional[int] = Field(None, alias="isCache")

    menu_type: Optional[str] = Field(None, alias="menuType")

    visible: Optional[str] = Field(None, alias="visible")

    status: Optional[str] = Field(None, alias="status")

    use_flag: Optional[str] = Field(None, alias="useFlag")

    perms: Optional[str] = Field(None, alias="perms")

    icon: Optional[str] = Field(None, alias="icon")

    create_by: Optional[str] = Field(None, alias="createBy")

    create_time: Optional[datetime] = Field(None, alias="createTime")

    update_by: Optional[str] = Field(None, alias="updateBy")

    update_time: Optional[datetime] = Field(None, alias="updateTime")

    remark: Optional[str] = Field(None, alias="remark")



class SysMenuCreate(SysMenuBase):
    pass


class SysMenuUpdate(SysMenuBase):
    pass


class SysMenuDelete(BaseModel):
    ids: List[int] = Field(..., description="菜单权限表ID列表")


class PageParams(BaseSchema):
    page_num: int = Field(1, ge=1, alias="pageNum", description="页码")
    page_size: int = Field(10, ge=1, le=100, alias="pageSize", description="每页数量")

    menu_name: Optional[str] = Field(None, alias="menuName")

    path: Optional[str] = Field(None, alias="path")

    component: Optional[str] = Field(None, alias="component")

    query: Optional[str] = Field(None, alias="query")

    route_name: Optional[str] = Field(None, alias="routeName")

    menu_type: Optional[str] = Field(None, alias="menuType")

    visible: Optional[str] = Field(None, alias="visible")

    status: Optional[str] = Field(None, alias="status")

    use_flag: Optional[str] = Field(None, alias="useFlag")

    perms: Optional[str] = Field(None, alias="perms")

    icon: Optional[str] = Field(None, alias="icon")

    create_by: Optional[str] = Field(None, alias="createBy")

    update_by: Optional[str] = Field(None, alias="updateBy")

    remark: Optional[str] = Field(None, alias="remark")
